﻿#region " | Copyright 2013 | "
/*
 * Copyright 2013
 * Author : Siriwat Suananpornpanit
 * Attibutes
 */
#endregion

using System;
using System.Reflection;
using System.Web.Mvc;

namespace Single_SignOn.Attributes
{
    [AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = true)]
    public class HttpParamActionAttribute: ActionNameSelectorAttribute {
        public override bool IsValidName(ControllerContext controllerContext, string actionName, MethodInfo methodInfo) {
            if (actionName.Equals(methodInfo.Name, StringComparison.InvariantCultureIgnoreCase))
                return true;

            if (!actionName.Equals("Action", StringComparison.InvariantCultureIgnoreCase))
                return false;

            var request = controllerContext.RequestContext.HttpContext.Request;
            return request[methodInfo.Name] != null;
        }
    }
}